package com.lmt.api;

import com.lmt.base.ResultData;
import com.lmt.entity.ResourceDownload;
import com.lmt.entity.search.ResourceDownloadSearch;
import com.lmt.service.ResourceDownloadService;
import com.lmt.util.RedisCacheUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Date 2018/07/17
 *
 * @author MT-Lin
 */
@RestController
@RequestMapping("/ResourceDownloadApi")
public class ResourceDownloadApi {

	private final ResourceDownloadService resourceDownloadService;

	private final RedisCacheUtil redisCacheUtil;

	@Autowired
	public ResourceDownloadApi(ResourceDownloadService resourceDownloadService, RedisCacheUtil redisCacheUtil) {
		this.resourceDownloadService = resourceDownloadService;
		this.redisCacheUtil = redisCacheUtil;
	}

	@RequestMapping("/save")
	public ResultData save(@RequestBody ResourceDownload resourceDownload) {
		resourceDownload.setUserId(redisCacheUtil.getUserId(resourceDownload));
		return this.resourceDownloadService.save(resourceDownload);
	}

	@RequestMapping("/search")
	public ResultData search(@RequestBody ResourceDownloadSearch resourceDownloadSearch) {
		resourceDownloadSearch.setUserId(redisCacheUtil.getUserId(resourceDownloadSearch));
		return this.resourceDownloadService.search(resourceDownloadSearch);
	}

}
